package com.elder.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.elder.business.domain.MemberLeaveRecord;
import com.elder.business.domain.MemberLeaveRecordDTO;
import com.elder.business.service.IMemberLeaveRecordService;
import com.elder.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.elder.common.annotation.Log;
import com.elder.common.core.controller.BaseController;
import com.elder.common.core.domain.AjaxResult;
import com.elder.common.enums.BusinessType;
import com.elder.common.utils.poi.ExcelUtil;
import com.elder.common.core.page.TableDataInfo;

/**
 * 员工请假Controller
 * 
 * @author elder
 * @date 2024-04-13
 */
@RestController
public class MemberLeaveRecordController extends BaseController
{
    @Autowired
    private IMemberLeaveRecordService memberLeaveRecordService;

    /**
     * 查询员工请假列表
     */
    @Anonymous
    @GetMapping("member/leave/list")
    public TableDataInfo list(String memberName,String startTime,String endTime,String status,Integer pageNum,Integer pageSize)
    {
        return  memberLeaveRecordService.getMemberLeaveRecordList(memberName,startTime,endTime,status,pageNum,pageSize);
    }

    @Anonymous
    @GetMapping("member/leave/oneself/list")
    public TableDataInfo getOneselflist(Long userId,String startTime,String endTime,String status,Integer pageNum,Integer pageSize)
    {
        return  memberLeaveRecordService.getOneMemberLeaveRecordList(userId,startTime,endTime,status,pageNum,pageSize);
    }
    /**
     * 导出员工请假列表
     */
    @Anonymous
    @Log(title = "员工请假", businessType = BusinessType.EXPORT)
    @PostMapping("member/leave/export")
    public void export(HttpServletResponse response, MemberLeaveRecord memberLeaveRecord)
    {
        List<MemberLeaveRecord> list = memberLeaveRecordService.selectMemberLeaveRecordList(memberLeaveRecord);
        ExcelUtil<MemberLeaveRecord> util = new ExcelUtil<MemberLeaveRecord>(MemberLeaveRecord.class);
        util.exportExcel(response, list, "员工请假数据");
    }

    /**
     * 获取员工请假详细信息
     */
    @Anonymous
    @GetMapping(value = "member/leave/{leaveId}")
    public AjaxResult getInfo(@PathVariable("leaveId") Long leaveId)
    {
        return success(memberLeaveRecordService.selectMemberLeaveRecordByLeaveId(leaveId));
    }

    /**
     * 新增员工请假
     */
    @Anonymous
    @Log(title = "员工请假", businessType = BusinessType.INSERT)
    @PostMapping("member/leave")
    public AjaxResult add(@RequestBody MemberLeaveRecordDTO memberLeaveRecord)
    {
        return toAjax(memberLeaveRecordService.insertMemberLeaveRecord(memberLeaveRecord));
    }

    /**
     * 修改员工请假
     */
    @Anonymous
    @Log(title = "员工请假", businessType = BusinessType.UPDATE)
    @PutMapping("/member/leave")
    public AjaxResult edit(@RequestBody MemberLeaveRecord memberLeaveRecord)
    {
        return toAjax(memberLeaveRecordService.updateMemberLeaveRecord(memberLeaveRecord));
    }

    /**
     * 删除员工请假
     */
    @Anonymous
    @Log(title = "员工请假", businessType = BusinessType.DELETE)
	@DeleteMapping("member/leave/{leaveIds}")
    public AjaxResult remove(@PathVariable Long[] leaveIds)
    {
        return toAjax(memberLeaveRecordService.deleteMemberLeaveRecordByLeaveIds(leaveIds));
    }

    @Anonymous
    @RequestMapping("member/leave/approval")
    public AjaxResult approval(Long leaveId,Long memberId,String status,String notes)
    {
        return toAjax(memberLeaveRecordService.approvalMemberLeave(leaveId,memberId,status,notes));
    }
}
